package com.xhj.xmly.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.xhj.xmly.R;
import com.xhj.xmly.bean.SmallIcon;

import java.util.Collection;
import java.util.List;

/**
 * Created by XHJ on 2016/12/7.
 */
public class RecommendIconAdapter extends RecyclerView.Adapter<RecommendIconAdapter.ViewHolder>{
    private Context context;
    private List<SmallIcon> list;

    public RecommendIconAdapter(Context context, List<SmallIcon> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.recommend_icon,parent,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }
    public void addAll(Collection<? extends SmallIcon> collection){
        list.addAll(collection);
        notifyDataSetChanged();
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.textView.setText(list.get(position).getTitle());
        Picasso.with(context).load(list.get(position).getCoverPath()).into(holder.imageView);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        private ImageView imageView;
        private TextView textView;
        public ViewHolder(View itemView) {
            super(itemView);
            imageView = ((ImageView) itemView.findViewById(R.id.recommend_vp_image01));
            textView = (TextView) itemView.findViewById(R.id.recommend_vp_text01);
        }
    }
}

